<template>
  <div>
    <!-- button按钮 -->
    <el-row>
      <el-button>默认按钮</el-button>
      <el-button type="primary">主要按钮</el-button>
      <el-button type="success">成功按钮</el-button>
      <el-button type="info">信息按钮</el-button>
      <el-button type="warning" round>警告按钮</el-button>
      <el-button type="danger" plain>危险按钮</el-button>
      <el-button type="danger" icon="el-icon-edit" circle></el-button>
      <el-button type="danger" icon="el-icon-delete-solid">删除</el-button>
    </el-row>
    <!-- 表格组件 -->
    <el-table
      :data="students"
      style="width: 100%"
      :row-class-name="tableRowClassName"
      size="mini"
    >
      <el-table-column prop="name" label="姓名" width="180"> </el-table-column>
      <el-table-column prop="age" label="年龄" width="180"> </el-table-column>
      <el-table-column prop="address" label="地址"> </el-table-column>
      <el-table-column prop="school" label="毕业学校"> </el-table-column>
      <el-table-column prop="school" label="毕业学校"> </el-table-column>
      <el-table-column prop="school" label="毕业学校"> </el-table-column>
      <el-table-column prop="school" label="毕业学校"> </el-table-column>
      <el-table-column prop="school" label="毕业学校"> </el-table-column>
    </el-table>

    <!-- dialog弹框 -->
    <el-button type="text" @click="open()">打开嵌套表单的 Dialog</el-button>

    <el-dialog title="注册" :visible.sync="dialogFormVisible">
      <!-- 表单 -->
      <el-form :model="form">
        <el-form-item label="用户名" :label-width="formLabelWidth">
          <el-input v-model="form.name" autocomplete="off"></el-input>
        </el-form-item>

        <el-form-item label="年级" :label-width="formLabelWidth">
          <el-select v-model="form.region" placeholder="请选择年级">
            <el-option label="区域一" value="shanghai"></el-option>
            <el-option label="区域二" value="beijing"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogFormVisible = false"
          >确 定</el-button
        >
      </div>
    </el-dialog>

    <!-- 分页组件 -->
    <el-pagination
      background
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-sizes="[5, 10, 15, 20]"
      :page-size="pageSize"
      layout="sizes, prev, pager, next, jumper,->,total"
      :total="total"
    >
    </el-pagination>
  </div>
</template>

<script>
export default {
  methods: {
    open() {
      this.dialogFormVisible = true;
    },
    tableRowClassName({ row, rowIndex }) {
      if (rowIndex === 1) {
        return "warning-row";
      } else if (rowIndex === 3) {
        return "success-row";
      }
      return "";
    },
    //当显示条数发生改变执行的函数
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
    },
    //当前也发生改变执行的函数
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
    },
  },
  data() {
    return {
      students: [
        {
          name: "刘德华",
          age: 35,
          address: "昆明",
          school: "理工",
        },
        {
          name: "刘德华",
          age: 35,
          address: "昆明",
          school: "理工",
        },
        {
          name: "刘德华",
          age: 35,
          address: "昆明",
          school: "理工",
        },
        {
          name: "刘德华",
          age: 35,
          address: "昆明",
          school: "理工",
        },
        {
          name: "刘德华",
          age: 35,
          address: "昆明",
          school: "理工",
        },
        {
          name: "刘德华",
          age: 35,
          address: "昆明",
          school: "理工",
        },
        {
          name: "刘德华",
          age: 35,
          address: "昆明",
          school: "理工",
        },
      ],
      currentPage: 1,
      total: 50,
      pageSize: 5,
      dialogFormVisible: false,
      formLabelWidth: "120px",
      form: {
        name: "",
        region: "",
      },
    };
  },
};
</script>

<style>
.el-table .warning-row {
  background: oldlace;
}

.el-table .success-row {
  background: #f0f9eb;
}
</style>